package gui.menus;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JMenu;
import javax.swing.JMenuItem;

import gui.Main.GUI;

/**
 * Represents the file Menu
 * 
 * @author msmith52
 *
 */
public class DebugFileMenu extends JMenu{

	/** Root the GUI **/
	private GUI main;
	
	/** Debug session menu */
	private DebugSessionMenu sessionMenu;
	
	/** Exit menu item */
	private JMenuItem saveHyPeerWeb;
	private JMenuItem deleteSegment;
	private JMenuItem exitGUI;
	
	/**
	 * Creates a Debug File Menu object
	 * @param main
	 */
	DebugFileMenu(GUI main)	{
		this.main = main;
		init();
	}
	
	/**
	 *  Initializes GUI components
	 */
	public void init()	{
		this.setText("File");
		
		sessionMenu = new DebugSessionMenu(main);
		this.add(sessionMenu);
		
		saveHyPeerWeb = new JMenuItem("Save and Close HyPeerWeb");
		saveHyPeerWeb.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				main.getHyPeerWeb().saveHyPeerWeb();
			}
		});
		this.add(saveHyPeerWeb);
		
		deleteSegment = new JMenuItem("Delete Segment");
		deleteSegment.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				main.getHyPeerWeb().deleteSegment();
			}
		});
		this.add(deleteSegment);
		
		exitGUI = new JMenuItem("Exit");
		exitGUI.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				main.getHyPeerWeb().disconnectFromGUI(main.getGlobalObjectId());
				System.exit(0);
			}
		});
		this.add(exitGUI);
	}
}
